home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Mac / IDE scripts / Widget demos / KeyTester.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  816 b   |  35 lines

  1. """Simple W demo -- shows how to make a window, and bind a function to a "key" event."""
  2.  
  3. import W
  4.  
  5. # key callback function
  6. def tester(char, event):
  7.     text = `char` + "\r" + `ord(char)` + "\r" + hex(ord(char)) + "\r" + oct(ord(char))
  8.     window.keys.set(text)
  9.  
  10. # close callback
  11. def close():
  12.     window.close()
  13.  
  14. # new window
  15. window = W.Dialog((180, 100), "Type a character")
  16.  
  17. # make a frame (a simple rectangle)
  18. window.frame = W.Frame((5, 5, -5, -33))
  19.  
  20. # some labels, static text
  21. window.captions = W.TextBox((10, 9, 43, -36), "char:\rdecimal:\rhex:\roctal:")
  22.  
  23. # another static text box
  24. window.keys = W.TextBox((60, 9, 40, -36))
  25.  
  26. # a button
  27. window.button = W.Button((-69, -24, 60, 16), "Done", close)
  28.  
  29. # bind the callbacks
  30. window.bind("<key>", tester)
  31. window.bind("cmdw", window.button.push)
  32.  
  33. # open the window
  34. window.open()
  35.